include $(TOPDIR)/rules.mk

PKG_NAME:=mihomo
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/MetaCubeX/mihomo.git
#PKG_SOURCE_DATE:=2025-11-14
PKG_SOURCE_VERSION=Alpha
PKG_SOURCE_VERSION:=c107c6a82488e470b3a7d75df25a883b3a495755
PKG_MIRROR_HASH:=0fffba048b9d9c1c3646043dc49b4dcbec557422db8beb5e1e546058d62ee0da

PKG_LICENSE:=MIT
PKG_MAINTAINER:=Joseph Mory <morytyann@gmail.com>

PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_PARALLEL:=1
PKG_BUILD_FLAGS:=no-mips16

#PKG_BUILD_VERSION:=alpha-fb464bb
PKG_BUILD_TIME:=$(shell date -u -Iseconds)

GO_PKG:=github.com/metacubex/mihomo
GO_PKG_LDFLAGS_X:=$(GO_PKG)/constant.Version=$(PKG_BUILD_VERSION) $(GO_PKG)/constant.BuildTime=$(PKG_BUILD_TIME)
GO_PKG_TAGS:=with_gvisor

include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk

define Package/mihomo
  SECTION:=net
  CATEGORY:=Network
  TITLE:=A rule based proxy in Go.
  URL:=https://wiki.metacubex.one
  DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle +curl +yq firewall4 +kmod-nft-tproxy +ip-full +kmod-tun +procd-ujail
  USERID:=mihomo=7890:mihomo=7890
endef

define Package/mihomo/description
  A rule based proxy in Go.
endef

define Package/mihomo/conffiles

endef

define Package/mihomo/install
	$(call GoPackage/Package/Install/Bin,$(1))
	
	$(INSTALL_DIR) $(1)/etc/openclash/core
	$(LN) /usr/bin/mihomo $(1)/etc/openclash/core/clash_meta
endef

define Package/mihomo/postrm
endef

define Build/Prepare
	$(Build/Prepare/Default)
	$(RM) -r $(PKG_BUILD_DIR)/rules/logic_test
endef

$(eval $(call GoBinPackage,mihomo))
$(eval $(call BuildPackage,mihomo))
